package com.hsc.www.stream0;

import net.dreamlu.mica.core.utils.$;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
public class Controller {
    @Autowired
    ServerProperties serverProperties;
    @Autowired
    MessageChannel output;


    @RequestMapping("send")
    public Object send() {

        Map map = new HashMap<>();
        map.put("time", $.formatDateTime(new Date()));
        map.put("port", serverProperties.getPort());

        Message message = MessageBuilder.withPayload($.toJson(map)).build();
        output.send(message);
        return map;
    }
}
